package com.yuexunit.finance.seal.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.seal.entity.SealInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年5月25日 下午1:54:30
*@author wenwenlong
*类说明
*/

@Implements(SealInfoService.class)
public class SealInfoServiceImpl implements SealInfoService {

	@Override
	@Transactional
	public Long createSealInfo(SealInfoEntity entity) {
		entity.setEnabled(Boolean.TRUE);
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getSealId();
	}

	@Override
	@Transactional
	public void updateSealInfo(SealInfoEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	@Transactional
	public void disableSealInfo(Long sealId) {
		SealInfoEntity entity = PersistUtil.get(SealInfoEntity.class, sealId);
		entity.setEnabled(Boolean.FALSE);
		PersistUtil.update(entity);
	}

	@Override
	public SealInfoEntity inquireSealInfoDetail(Long sealId) {
		return PersistUtil.get(SealInfoEntity.class, sealId);
	}

	@Override
	public List<SealInfoEntity> inquireSealInfoList(Long enterpriseId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SealInfoEntity.class);
		if (null != enterpriseId) {
			criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		return PersistUtil.get(criteria);
	}
}
